home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Environments / Prograph Classic 2.6.1 / Prograph Tutorial Manual / Prograph Tutorial / Prograph Tutorial.rsrc / TEXT_152.txt < prev    next >
Encoding:
Text File  |  1995-10-16  |  10.3 KB  |  250 lines

  1.  
  2. t    Breakpoints and the Stack Window
  3.  
  4. *107*This portion of the tutorial introduces the*998* Stack window and the various*327* Exec *609*menu items that help you control and examine Prograph classes and methods while your application is running. The Prograph editor and interpreter are designed to work together during application development. A variety of runtime facilities help you examine and edit all aspects of your application as it runs.
  5.  
  6. u    Delete the test method from the Universal Methods window.
  7.  
  8. u    Selectively load the quickSort universal method from the Algorithms.pgs file in the Tutorial Examples Δí folder.  Select*667* *1080*Tidy Icons *1175*from the*1184* Windows menu to bring the quickSort method into view, if necessary.
  9.  
  10. u    Open the quickSort method and inspect its two cases.
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32. The quickSort expects a list as input, which it sorts using a list-partitioning multiplex and recursive reference to itself in its second case. When done, quickSort passes the sorted list out its output. While its second case may not make sense to you now, using the Prograph Stack window and breakpoints can help you to understand quickly how this method works.
  33.  
  34. u    Bring the case window quickSort 1:2 topmost and active. Click to select the Match operation, which is checking for an empty-list condition. Select*112* *330*Breakpoint On *611*from the Exec menu. 
  35.  
  36. ___________________________________________________________
  37. NOTE:  The Debug menu item in the Exec menu must be on (checked) for breakpoints and step/show mode to be enabled.
  38. -----------------------------------------------------------
  39.  
  40. u    Command-click the close box to close both case windows of the quickSort method.
  41.  
  42. u    Create a universal method, Do Sort, which looks like this:
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58. u    Close the Do Sort 1:1 case window and, while the Do Sort method icon is selected in the now-active Universal window, select*339* *981*Set Program *620* from the Exec menu. This lets you execute and stop executing the Do Sort method with a simple Command-R. If Set Program is not used, you have to select the Do Sort icon in the Universal window (or alternatively bring the Do Sort 1:1 case window to the front) and select the Execute Method item in the Exec menu each time you want to do the sort.
  59.  
  60. u    Select*666* *996*Stack from the*663* *1185*Windows menu. The tall, narrow Stack window opens to the right of the Universal and Classes windows.
  61.  ¬†
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80. ===========================================================
  81. TIP:  You can move these and any other Prograph windows around to your*1098* liking and select the*943* Remember Windows *1187*item under the*665* Windows menu to have Prograph maintain your own preferred window configuration.
  82. ===========================================================
  83.  
  84. The*1188* Stack window title has an icon that looks like a stack of plates. Its window pane is also shaded with the same gray pattern found in a*1084* method-execution window. These visual cues identify the*999* Stack window as one of the windows in which Prograph lets you inspect, but not edit, methods during execution. 
  85.  
  86. The icons displayed in the Stack and execution windows are not directly editable. Double-clicking method icons in the Stack window opens their respective execution case windows. Double-clicking the background and roots or terminals in an execution case window opens editable case or Value windows, respectively. If the double-clicked elements are not editable, such as primitives, the ÀôInfo‚Ķ dialog is opened to the appropriate category, with the clicked item selected in the scroll list.  To see the Stack window in action:
  87.  
  88. u    Press Command-R to run Do Sort. The Classes and Universal windows close, and the Stack window displays an icon.
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96. At first glance, Stack window method icons look like icons in the Universal Methods window or those in class Methods windows. On closer inspection, you see the addition of a*1002* case-number reference in the center of the icon. The Stack window excerpt above indicates that case #1 of the Do Sort method is executing. Since it is the first icon to be displayed under the fuzzy gray line*1003* that appears at the top of the Stack window indicating current execution, you know that Do Sort is the first method to execute upon selecting Run Do Sort from the Exec menu.
  97.  
  98. This first entry in the Stack window is almost immediately obscured by the Enter list:‚Ķ dialog that results from execution of the Do Sort operations:
  99.  
  100. u    Type (3 8 2 6) in response to the dialog:
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123. u    Press Return to dismiss the dialog. The Stack window updates. Case #1 of quickSort is executing, which results in the execution flow being interrupted by the Breakpoint you set on the Match operation. The Stack window now displays a second method icon, indicating that the first case of quickSort is executing.
  124.  
  125. u    Press Return. The match on the empty-list condition fails, and quickSort calls its second case. The quickSort 1:1 execution window closes, the quickSort 2:2 window opens, and the Stack window‚Äôs quickSort method icon is updated to reflect the execution of case #2.
  126.  
  127. u    Press Return one more time.
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152. u    To see the relationship between the Do Sort and quickSort execution icons in the Stack window, activate the Stack window and double-click the Do Sort icon. An execution window opens on Do Sort 1:1 and indicates that the ask operation has received its user response and has passed its output to a quickSort operation.
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178. u    Double-click on the terminal of the quickSort operation in the Do Sort execution window to open a Value window that confirms that the list, (3 8 2 6), is flowing into quickSort. Dismiss the Value window and the Do Sort 1:1 execution window.
  179.  
  180. ___________________________________________________________
  181. NOTE:  The*1100* Stack window provides a powerful overview of what is happening in your program. The ability to open execution windows on methods that are pending completion gives you a closer look at how your application got to its present state.
  182.  
  183. Open an execution window on a still-not-completed method by double-clicking its icon in the Stack window. The highlighted icon in the method execution window is the operation calling the method next down in the Stack window. The terminal of the highlighted operation displays a hollow circle, indicating that data has arrived to that point. The output roots of the highlighted operation remain gray, indicating that no output has yet resulted.
  184. -----------------------------------------------------------
  185.  
  186. u    Continue pressing Return to step deeper and deeper into the quickSort recursive algorithm. Activity pops back and forth between the execution windows of the first and second case of quickSort, revealing the progress of the sort. Each change in the selection of the active execution window coincides with an update of the Stack window. At its deepest level of recursion during this example, the Stack window looks like this.
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206. u    Continue pressing Return. Once it has ‚Äúbottomed out,‚Äù the recursion starts to unravel itself, resolving pending executions and joining sorted sublist to sublist. When the first call to quickSort joins the last two sorted sublists, its execution is finished. The fully sorted list is output from the quickSort operation in the Do Sort method. Do Sort is completed, and the show operation confirms the result:
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226. u    Dismiss the results dialog. The Do Sort method icon in the Stack window disappears. The Stack window is now empty, indicating that this mini-application has completed execution. 
  227. Close the Stack window if it is still open.
  228.  
  229. Here the*108* Breakpoint you set in quickSort forced the interpreter into the stepping process, which allowed you to inspect the sorting algorithm as it proceeded. You were ready for the process with the Stack window open and the Breakpoint set. But what about the more typical scenario in which you decide to inspect program execution during runtime?
  230.  
  231. u    Open the quickSort 1:2 case window and select the Match operation. Select Breakpoint Off from the Exec menu.
  232.  
  233. u    Select Run Do Sort from the Exec menu and at the Enter list: prompt type a reasonably large list, such as:
  234.  
  235.  (45 3 7 3 8 6 9 2 21 64 3 6 7 34 2 1 21 27 13 33 1 5 56 28 2 4 7)
  236.  
  237.  and press Return.
  238.  
  239. u    Quickly issue the Prograph Break*104* command by pressing Command-. (Command and the period key) to interrupt execution. The Stack window opens together with the execution window of the method currently in the midst of executing.
  240.  
  241. You can inspect the execution window as before. If you activate the Stack window, you can scroll up and down the list and peek into the still pending executions of the second case of quickSort.
  242.  
  243. u    Press Return. Execution resumes with the Stack window still open. This slows execution down considerably because of all the window-animation updating. But watching the Stack window activity reveals a great deal about how your methods and their cases relate and call upon each other. You can issue the Break command (Command-.) any time to interrupt your application and open the execution window for the currently executing method.
  244.  
  245. The list of pending method executions in the Stack window keeps growing as sublists are partitioned. Eventually, the sort algorithm ‚Äúbottoms out‚Äù and the sublists are put back together. As second cases of quickSort are resolved, they disappear from the bottom of the Stack window list until all are gone and the show‚Ķ dialog pops up displaying the sorted long list. Only the Do Sort method is pending execution completion in the Stack window. 
  246.  
  247. u    Dismiss the sorted-list dialog. Do Sort finishes execution, and its method icon is removed from the Stack window. Prograph returns to the editor with whatever windows were open when you ran Do Sort. Close the Stack window if it is still open. 
  248.  
  249. The Stack window is one of the most useful interpreter facilities for learning what a Prograph application is doing as it runs. The Stack window can be opened any time you suspend execution of an application. So far, you have suspended execution with a*109* Breakpoint and Break command. As you explore interpreter features, notice that some automatically open the Stack window. Don‚Äôt hesitate to investigate opening the Stack window on your own as you practice techniques for interrupting and inspecting Prograph method execution in the next section of the tutorial.
  250.